#多重构建，方法一
FROM golang:1.17 AS build
WORKDIR /module03_docker/
COPY . .
ENV CGO_ENABLED=0
ENV GO111MODULE=auto
ENV GOPROXY=https://goproxy.cn,direct
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -installsuffix cgo -o httpserver main.go

FROM scratch
COPY --from=build/module03_docker/httpserver /httpserver/httpserver
EXPOSE 80
ENV ENV local
WORKDIR /httpserver/
ENTRYPOINT ["./httpserver"]



#比较简洁的写法

FROM golang:1.17 AS builder

ENV GO111MODULE=off \
	CGO_ENABLED=0 \
	GOOS=linux \
	GOARCH=amd64

WORKDIR /module03_docker
COPY . .
RUN go build -o httpserver .

FROM scratch
COPY --from=builder/module03_docker/httpserver/
EXPOSE 80
ENTRYPOINT ["/httpserver"]
